var imgSrc1 = []; //图片路径
var imgFile1 = []; //文件流
var imgName1 = []; //图片名字
//选择图片
function imgUpload1(obj) {
	var username = '#' + obj.username;
	var oInput1 = '#' + obj.inputId;
	var imgBox1 = '#' + obj.imgBox;
	$(oInput1).on("change", function() {
		var fileImg = $(oInput1)[0];
		var fileList = fileImg.files;
		for(var i = 0; i < fileList.length; i++) {
			var imgSrcI = getObjectURL(fileList[i]);
			imgName1.push(fileList[i].name);
			imgSrc1.push(imgSrcI);
			imgFile1.push(fileList[i]);
			
			var formFile = new FormData();
			formFile.append("action", "UploadVMKImagePath");  
            formFile.append("file", fileList[i]); //加入文件对象
            formFile.append("title", $(oInput1).attr("title"));
            formFile.append("username", $(username).val());
            var data = formFile;
            $.ajax({
                url: obj.upUrl,
                data: data,
                type: "Post",
                dataType: "json",
                cache: false,//上传文件无需缓存
                processData: false,//用于对data参数进行序列化处理 这里必须false
                contentType: false, //必须
                success: function (result) {
                	var url = $("#photo1").val();
                	var urls = (url == "")?result.photoPath:(url+","+result.photoPath)
                	$("#photo1").val(urls);
                },
            });
			
		}
		
		addNewContent1(imgBox1);
	})

}
//图片展示
function addNewContent1(obj) {
	$(imgBox1).html("");
	for(var a = 0; a < imgSrc1.length; a++) {
		var oldBox = $(obj).html();
		$(obj).html(oldBox + '<div class="imgContainer"><img class="img-u" title=' + imgName1[a] + ' alt=' + imgName1[a] + ' src=' + imgSrc1[a] + ' onclick="imgDisplay1(this)"><p onclick="removeImg1(this,' + a + ')" class="imgDelete">删除</p></div>');
	}
}
//删除
function removeImg1(obj, index) {
	imgSrc1.splice(index, 1);
	imgFile1.splice(index, 1);
	imgName1.splice(index, 1);
	var boxId = "#" + $(obj).parent('.imgContainer').parent().attr("id");
	addNewContent1(boxId);
}

//图片灯箱
function imgDisplay1(obj) {
	var src = $(obj).attr("src");
	var imgHtml = '<div style="width: 100%;height: 100vh;overflow: auto;background: rgba(0,0,0,0.5);text-align: center;position: fixed;top: 0;left: 0;z-index: 1000;"><img class="img-u" src=' + src + ' style="margin-top: 100px;width: 70%;margin-bottom: 100px;"/><p style="font-size: 50px;position: fixed;top: 30px;right: 30px;color: white;cursor: pointer;" onclick="closePicture1(this)">×</p></div>'
	$(imgBox1).append(imgHtml);
}
//关闭
function closePicture1(obj) {
	$(obj).parent("div").remove();
}
//图片预览路径
function getObjectURL(file) {
	var url = null;
	if(window.createObjectURL != undefined) { // basic
		url = window.createObjectURL(file);
	} else if(window.URL != undefined) { // mozilla(firefox)
		url = window.URL.createObjectURL(file);
	} else if(window.webkitURL != undefined) { // webkit or chrome
		url = window.webkitURL.createObjectURL(file);
	}
	return url;
}